/**
 *
 */
package com.yangtao.prototype.system.dao;

import com.yangtao.framework.common.Pagination;
import com.yangtao.framework.hibernate.BaseDao;
import com.yangtao.prototype.PrototypeConstant;
import com.yangtao.prototype.system.domain.LogNote;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author 杨涛
 * @version 1.0
 * @date 2011-3-23
 */
@Repository
public class LogNoteDao extends BaseDao<LogNote> {

	public void addCustomCriterion(Criteria criteria) {
		criteria.addOrder(Order.desc("logInTime"));
	}

	public Pagination findOnLineUser(Pagination page) {
		page.setNumRows(Long.valueOf(findUnique(
				"select count(*) from LogNote ln where ln.state=?", PrototypeConstant.LOGON_STATE)
				.toString()));
		page.setItems(find("from LogNote ln where ln.state=?", PrototypeConstant.LOGON_STATE));
		return page;
	}

	public void logOut(String id) {
		String hql = "update LogNote set logOutTime=?,state=? where id=?";
		batchExecute(hql, new Date(), PrototypeConstant.LOGOFF_STATE, id);
	}
}
